<template>
  <el-container>
    <el-header>社区资讯</el-header>
    <el-container>
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1','2']">
          <el-submenu index="1">
            <template slot="title"><i class="el-icon-message"></i>最新热点</template>
            <el-menu-item-group>
              <el-menu-item index="1-1">
                <router-link to="/hot_search" tag="li">百度热搜</router-link>
              </el-menu-item>
              <el-menu-item index="1-2">
                <!-- <router-link :to="{path:'/epidemic_situation', params: {id:1}}" tag="li">最新疫情</router-link> -->
                <li @click="link">最新疫情</li>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title"><i class="el-icon-message"></i>社区公告</template>
            <el-menu-item-group>
              <el-menu-item index="2-1">
                <router-link to="/activity" tag="li">活动公告</router-link>
              </el-menu-item>
              <label>
                <el-menu-item id="test_type" index="2-2">
                  <router-link to="/importantMatters" tag="li">重要事宜公告</router-link>
                </el-menu-item>
              </label>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
  //应用定位功能
  import BMap from "BMap"
  export default {
    data() {
      return {
        //疫情信息的定位信息
        aaa:'1',
        musicTypeJSON: {},
        searchValue: "",
        result: [],
        titleTypeJSON: {}, //热门城市
        LocationCity: "正在定位...", //一个初始值
      }
    },
    methods: {
      //跳转
      link(){
        console.log(this.aaa)
        this.$router.push({path:'/epidemic_situation',query: {url:this.aaa}})
      },
      city() {
        //定义获取城市方法
        const geolocation = new BMap.Geolocation();
        let _this = this;
        geolocation.getCurrentPosition(
          function getinfo(position) {
            let city = position.address.city; //获取城市信息
            let province = position.address.province; //获取省份信息
            console.log(position);
            console.log(position.address.city);
            console.log(position.address.province);
            _this.LocationCity = city;
            //跳转并且带参数
            //裁剪字符串
            let newcity=city.slice(0,city.length-1)
            console.log(newcity)
            let newprovince=province.slice(0,province.length-1)
            console.log(newcity)
            _this.aaa=newprovince+"-"+newcity;
            console.log(_this.aaa)
          },
          function(e) {
            _this.LocationCity = "定位失败";
          }, {
            provider: "baidu"
          }
        );
      }
    },
    created() {
      this.city();
    }
  }
</script>

<style>
</style>
